package com.hzeport.bgs22emduty.inbound.api;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hzeport.bgs22emduty.entity.BaseDeptInfo;
import com.hzeport.bgs22emduty.service.BaseDeptInfoService;
import com.masa.common.core.base.BaseResult;
////////import com.masa.common.log.annotation.SysLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * ${comments}
 *
 * @author code generator
 * @date 2022-12-02 11:21:59
 */
@RestController
@AllArgsConstructor
@RequestMapping("/basedeptinfo")
@Api(value = "basedeptinfo", tags = "${comments}管理")
@Slf4j
public class BaseDeptInfoController {

    private final BaseDeptInfoService baseDeptInfoService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param baseDeptInfo ${comments}
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page")
    public BaseResult getBaseDeptInfoPage(Page page, BaseDeptInfo baseDeptInfo) {
        return BaseResult.ok(baseDeptInfoService.page(page, baseDeptInfo));
    }


    /**
     * 通过id查询${comments}
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}")
    public BaseResult getById(@PathVariable("id") String id) {
        return BaseResult.ok(baseDeptInfoService.getById(id));
    }

    /**
     * 新增${comments}
     * @param baseDeptInfo ${comments}
     * @return R
     */
    @ApiOperation(value = "新增${comments}", notes = "新增${comments}")
    //////@SysLog(.*)
    @PostMapping
    public BaseResult save(@RequestBody BaseDeptInfo baseDeptInfo) {
        return BaseResult.ok(baseDeptInfoService.save(baseDeptInfo));
    }

    /**
     * 修改${comments}
     * @param baseDeptInfo ${comments}
     * @return R
     */
    @ApiOperation(value = "修改${comments}", notes = "修改${comments}")
    //////@SysLog(.*)
    @PutMapping
    public BaseResult updateById(@RequestBody BaseDeptInfo baseDeptInfo) {
        String id = baseDeptInfo.getId();
        if (StringUtils.isNotBlank(id)) {
            BaseDeptInfo byId = baseDeptInfoService.getById(id);
            if (byId != null){
                baseDeptInfo.setRecVersion(byId.getRecVersion());
            }
        }
        return BaseResult.ok(baseDeptInfoService.updateById(baseDeptInfo));
    }

    /**
     * 通过id删除${comments}
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除${comments}", notes = "通过id删除${comments}")
    ////////@SysLog(.*)
    @DeleteMapping("/{id}")
    public BaseResult removeById(@PathVariable String id) {
        return BaseResult.ok(baseDeptInfoService.removeById(id));
    }

}
